package com.axialproject.health.exchange.allergytracker;

import com.axialproject.health.exchange.ConnectorListener;
import com.axialproject.health.exchange.Record;
import com.axialproject.health.exchange.entity.Patient;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;

public class ConnectorServlet extends ConnectorListener {

    @Override
    protected Record getRecord(HttpServletRequest req) {
        return null;
    }

    @Override
    protected Patient getPatient(HttpServletRequest req) {
        return null;
    }

    /*
    @Override
    protected Record getRecord(HttpServletRequest req) {
        Record record = new Record ();
        record.setType("allergy");
        record.setStart(new Date ());
        record.setStop(new Date ());
        record.setDescription(req.getParameter("note"));

        String [] allergies = req.getParameterValues("allergies");
        if (allergies == null) {
            allergies = new String [0];
        }
        ArrayList <String> allergens = new ArrayList <String> ();
        ArrayList <String> severities = new ArrayList <String> ();
        for (String allergy : allergies) {
            List <String> comps = parseInputParameter (allergy);
            allergens.add (comps.get(0));
            severities.add (comps.get(1));
        }
        record.setAllergyAllergens(allergens);
        record.setAllergySeverities(severities);

        return record;
    }

    @Override
    protected Patient getPatient(HttpServletRequest req) {
        Patient patient = null;
        EntityManager em = EMF.get().createEntityManager();
        try {
            patient = PatientManager.getPatientByUsernameAppName(em, req.getParameter("username"), "allergytracker");
        } catch (Exception e) {
        } finally {
            em.close ();
        }
        return patient;
    }
    */

    @Override
    protected String[] getDestinations(HttpServletRequest req) {
        ArrayList <String> ds = new ArrayList <String> ();
        ds.add ("google");
        return ds.toArray(new String [0]);
    }

    @Override
    protected String getAppName() {
        return "allergytracker";
    }

}
